﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Data;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;
using System.Web.UI.HtmlControls;
using System.Configuration;
using System.Security;



namespace SocialKlee.DataAccessLayer
{
    /// <summary>
    /// Summary description for Class1
    /// </summary>
    public class DALayer
    {
        public DALayer()
        {
            //
            // TODO: Add constructor logic here
            //
        }
       
        public static string ExecuteStoreProcedure(string ConnectionString, SqlCommand sqlCommand)
        {

            try
            {
                SqlConnection myConn = new SqlConnection(ConnectionString);
                myConn.Open();
                SqlTransaction sqlTrans;
                sqlTrans = myConn.BeginTransaction();
                sqlCommand.Connection = myConn;
                sqlCommand.Transaction = sqlTrans;  
                sqlCommand.ExecuteNonQuery();
                sqlTrans.Commit();
                myConn.Close();     
                return "Success";

                // return SocialKlee.Constants.SLConstants.SuccessMessage;
                //return StreamLink.Constants.SLConstants.SuccessMessage;
            }
            catch (SqlException e)
            {
                return "Failure";
            }
        }

             #region GetDataTableWithProcedure
        public static DataTable GetDataTableProc(string ConnectionString, SqlCommand sqlCommand)
        {
            SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);

            sqlCommand.Connection = myConn;
            sqlCommand.CommandType = CommandType.StoredProcedure;

            SqlDataAdapter myDap = new SqlDataAdapter(sqlCommand);
            DataTable dt = new DataTable();
            myDap.SelectCommand = sqlCommand;
            myDap.Fill(dt);
            return dt;
        }
        #endregion

        #region GetDataTable
        public static DataTable GetDataTable(string sqlQuery)
        {
            SqlConnection myConn = new SqlConnection(ConfigurationManager.AppSettings["ConnectionString"]);
            SqlCommand myComm = new SqlCommand();
            myComm.Connection = myConn;
            myComm.CommandType = CommandType.Text;
            myComm.CommandText = sqlQuery;
            SqlDataAdapter myDap = new SqlDataAdapter();
            DataTable dt = new DataTable();
            myDap.SelectCommand = myComm;
            myDap.Fill(dt);
            return dt;
        }
        #endregion



    }
}

